<?php

namespace App\Http\Requests\Admin\Store;

use App\Http\Requests\ApiRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

/**
 * @property mixed account
 * @property mixed password
 * @property string device_name
 * @property int skin_detector_id
 */
class DeviceAccountUpdateRequest extends ApiRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $id = last(explode('/', $this->url()));

        return [
            'account'          => ['required', 'string', 'max:'.self::MAX_STRING, Rule::unique('device_accounts', 'account')->ignore($id)],
            'password'         => 'nullable|string|min:6|max:'.self::MAX_STRING,
            'device_name'      => 'nullable|string|max:'.self::MAX_STRING,
            'skin_detector_id' => 'nullable|int',
        ];
    }

    /**
     * @return array
     */
//    public function messages()
//    {
//        return [
//            'account.*'          => '账号已注册，请尝试其他账号',
//            'password.*'         => '设备账号密码必须是字符串',
//            'device_name.*'      => '设备名称必须是字符串',
//            'skin_detector_id.*' => '设备账号关联的肤质检测仪',
//        ];
//    }
}
